﻿using Collection.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WanPiJie;
using WanPiJie.Products;

namespace Collection.Export.Services.Wanpijie
{
    public static class ClassExtension
    {
        /// <summary>
        /// 将采集的属性信息转换为顽皮街属性
        /// </summary>
        /// <param name="_this">采集的原始属性信息</param>
        /// <returns>顽皮街属性信息</returns>
        public static ProductAttribute ToProductAttribute(this	Property _this)
        {
            WanPiJie.Products.Catalog wpjCatalog = WpjSf.CategoryService.GetCatalogByThirdId(_this.CatalogId);
            WanPiJie.Products.Attribute attribute = WpjSf.CategoryService.GetAttributeByThirdId(_this.Id);
            ProductAttribute productAttribute = new WanPiJie.Products.ProductAttribute
            {
                CatalogId = wpjCatalog.Id,
                AttributeId = attribute.Id,
                Name = attribute.Name
            };
            return productAttribute;
        }

        /// <summary>
        /// 将采集的属性值属性信息转换为顽皮街的商品属性值数据
        /// </summary>
        /// <param name="_this">商品属性值数据</param>
        /// <returns>顽皮街街属性值对象</returns>
        public static ProductAttributeValue ToProductAttributeValue(this	PropertyValue _this)
        {
            WanPiJie.Products.Catalog wpjCatalog = WpjSf.CategoryService.GetCatalogByThirdId(_this.CatalogId);
            WanPiJie.Products.Attribute attribute = WpjSf.CategoryService.GetAttributeByThirdId(_this.PropertyId);
            ProductAttributeValue attributeValue = new ProductAttributeValue
            {
                CatalogId = wpjCatalog.Id,
                ThirdId = _this.Id,
                AttributeId = attribute.Id,
                Value = _this.Name
            };
            return attributeValue;
        }
    }
}
